package com.example.je_0309;


import jakarta.servlet.Servlet;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RequestMapping("/response")
//@RestController
@Controller
public class ResponseController {
    @RequestMapping("/test")
    public String test(){
        return "/test.html";
    }

    @ResponseBody
    @RequestMapping("/testData")
    public String testData(){
        return "返回数据";
    }

    @ResponseBody
    @RequestMapping("/testData2")
    public String testData2(){
        return "<h1> hello world!</h1>";
    }

    @ResponseBody
    @RequestMapping(value = "/getMap",produces = "application/json")
    public HashMap<String,String> getMap(){
        HashMap<String,String> map = new HashMap<>();
        map.put("k1","v1");
        map.put("k2","v2");
        map.put("k3","v3");
        map.put("k4","v4");
        return map;
    }


    @ResponseBody
    @RequestMapping(value = "/setStatus",method =  RequestMethod.GET )
    public String setStatus(HttpServletResponse response){
        response.setStatus(418);
        return "设置成功";
    }

    @ResponseBody
    @RequestMapping(value = "/setContentType",produces = "application/json")
    public String setContentType(){
        return "{\"OK\":1}";
    }
}
